<template>
	<view>
		<my-search @my-click="gotosearch"></my-search>
		<view class="scroll_content">
		
				<scroll-view class="left" scroll-y="true" :style="{height: wxh + 'px'}">
					<block v-for="(item,index) in classifylist" :key="index">
						<view :class="['scroll_left_item',index === active ? 'active' : '']" @click="changeindex(index)">{{item.cat_name}}</view>
					</block>
					
				</scroll-view>
		
	
				<scroll-view class="right" :scroll-top="scrolltop" scroll-y="true" :style="{height: wxh + 'px'}">
						<view class="fl_title" v-for="(item2,index) in classifylsit2" :key="index">
							/ {{item2.cat_name}} /
							
							<view class="fl_content">
								<view class="fl_content_item" v-for="(item3,index) in item2.children" :key="index" @click="gotogoodlist(item3)">
									<image :src="item3.cat_icon"></image>
									<text class="content_span">{{item3.cat_name}}</text>
								</view>
							</view>
							
						</view>
						
						
						
					</scroll-view>	
		</view>
	</view>
	
</template>

<script>
	import bdage from '@/mixins/tabbar-baage.js'
	export default {
		mixins: [bdage],
		data() {
			return {
				wxh: 0,
				classifylist: [],
				active: 0,
				classifylsit2: [],
				scrolltop: 0
			};
		},
		onLoad () {
			this.getwxh()
			this.getclassifylist()
		},
		methods: {
			getwxh () {
				const xh = uni.getSystemInfoSync()
				this.wxh = xh.windowHeight - 50
				console.log(this.wxh)
			},
			async getclassifylist () {
				const {data: res} = await uni.$http.get('/api/public/v1/categories')
				if (res.meta.status !== 200) return uni.$showmsg('获取分类数据失败')
				this.classifylist = res.message
				this.classifylsit2 = res.message[0].children
			},
			changeindex (index) {
				this.active = index
				this.classifylsit2 = this.classifylist[index].children
				this.scrolltop = this.scrolltop === 0 ? 1 : 0
			},
			gotogoodlist (item3) {
				uni.navigateTo({
					url: '../../subpkg/shop_list/shop_list?cid=' + item3.cat_id
				})
			},
			gotosearch () {
				uni.navigateTo({
					url: '../../subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
.scroll_content {
	display: flex;
	.left {
		width: 120px;
	}
	.scroll_left_item {
		line-height: 60px;
		text-align: center;
		font-size: 12px;
		background-color: #F7F7F7;
	}
	.active {
		background-color: #FFFFFF;
		position: relative;
	}
	.active::after {
		content: "";
		width: 3px;
		height: 30px;
		display: block;
		background-color: #C00000;
		position: absolute;
		top: 50%;
		left: 0;
		transform: translateY(-50%);
	}
	.fl_title {
		font-size: 12px;
		font-weight: blod;
		text-align: center;
		padding: 15px 0;
	}
	.fl_content {
		display: flex;
		flex-wrap: wrap;
		padding: 0 10px;
		.fl_content_item {
			width: 33.3%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			image {
				width: 60px;
				height: 60px;
			}
			.content_span {
				font-size: 12px;
			}
		}
	}
}
</style>

